package com.leejxx.health.controller;

import com.leejxx.health.common.MessageConst;
import com.leejxx.health.entity.PageResult;
import com.leejxx.health.entity.QueryPageBean;
import com.leejxx.health.entity.Result;
import com.leejxx.health.pojo.CheckItem;
import com.leejxx.health.service.CheckItemService;
import com.leejxx.health.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author LeeJx
 * @ClassName CheckItemController
 * @Description TODO
 * @date 2020/12/30 11:29
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/checkItem")
public class CheckItemController {
    @DubboReference
    private CheckItemService checkItemService;
    @Autowired
    private RedisTemplate redisTemplate;

    @PreAuthorize("hasAuthority('CHECKITEM_QUERY')")
    @RequestMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean) {
        log.info("[检查项管理-分页查询]data:{}", queryPageBean);
        PageResult pageResult = checkItemService.findByPage(queryPageBean);
        log.info("[检查项管理-分页查询]data:{}", pageResult);
        return new Result(true, MessageConst.QUERY_CHECKITEM_SUCCESS, pageResult);
    }

    @PreAuthorize("hasAuthority('CHECKITEM_ADD')")
    @RequestMapping("/add")
    public Result add(@RequestBody CheckItem checkItem) {
        log.info("[检查项管理-增加项目]data:{}", checkItem);
        checkItemService.add(checkItem);
        return new Result(true, MessageConst.ADD_CHECKITEM_SUCCESS);
    }

    @PreAuthorize("hasAuthority('CHECKITEM_QUERY')")
    @RequestMapping("/findByCode")
    public Result findByCode(Integer code) {
        log.info("[检查项管理-修改回显]data:{}", code);
        CheckItem checkItem = checkItemService.findByCode(code);
        log.info("[检查项管理-修改回显]data:{}", checkItem);
        return new Result(true, MessageConst.QUERY_CHECKITEM_SUCCESS, checkItem);
    }

    @PreAuthorize("hasAuthority('CHECKITEM_EDIT')")
    @RequestMapping("/edit")
    public Result edit(@RequestBody CheckItem checkItem) {
        log.info("[检查项管理-修改项目]data:{}", checkItem);
        checkItemService.edit(checkItem);
        return new Result(true, MessageConst.EDIT_CHECKITEM_SUCCESS);
    }

    @PreAuthorize("hasAuthority('CHECKITEM_DELETE')")
    @RequestMapping("/delete")
    public Result delete(Integer code) {
        log.info("[检查项管理-删除项目]data:{}", code);
        checkItemService.delete(code);
        return new Result(true, MessageConst.DELETE_CHECKITEM_SUCCESS);
    }
}
